package com.wisemoresystem.seal.action.empower;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.model.t_empower;
import com.wisemoresystem.seal.service.EmpowerService;

/**
 * 转授权人员上限配置
 * 
 * @author Administrator
 *
 */
@Controller("ixEmpower")
@Scope("prototype")
@RequestMapping("/ix/empower")
public class EmpowerAction extends ProjBaseAction {

	@Autowired
	private EmpowerService empowerservice;

	/**
	 * 转授权人员列表
	 * 
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list() {
		List<Map<String, Object>> list = empowerservice.findEmpower();

		t_empower empower = new t_empower();
		if (ChkTools.isNotNull(list)) {
			String id = list.get(0).get("_id").toString();
			empower = oc.findObjById(id, t_empower.class);
		} else {
			empower.setNote("新建");
			oc.saveObj(empower);
		}

		ModelAndView mv = new ModelAndView("/jsp/empower/list");
		mv.addObject("empower", empower);
		return mv;
	}

	/**
	 * 转授权人员上限修改
	 * 
	 * @param id
	 * @param num
	 * @throws IOException
	 */
	@RequestMapping("/edit")
	public void edit(String id, String num) throws IOException {
		resp.setCharacterEncoding("utf-8");

		t_empower empower = oc.findObjById(id, t_empower.class);
		empower.setNum(Integer.parseInt(num));
		oc.updateObj(empower);

		logT.logH("修改被转授权人员上限", t_empower.class, empower.get_id());

		resp.getWriter().print("success");
		resp.getWriter().flush();

	}

}
